package MyGO.dao.impl;

import MyGO.dao.IDoctorDao;
import MyGO.entity.Doctor;
import MyGO.utils.FileUtils.FileIO;
import MyGO.utils.enumerastion.Department;
import MyGO.utils.enumerastion.DoctorLevel;
import MyGO.utils.enumerastion.VisTiOnDay;
import com.fasterxml.jackson.core.type.TypeReference;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class DoctorImpl implements IDoctorDao {
    private static List<Doctor> DOCTOR_LIST = new ArrayList<>();
    private static  HashMap<String, Doctor> DOCTOR_HASH_MAP = new HashMap<>();
    static  {
//        Doctor doctor1 = new Doctor("111", 2, 0,  "李一", "123liyi", Department.INTERNAL, DoctorLevel.PROFESSOR, VisTiOnDay.MORNING, 15.0);
//        Doctor doctor2 = new Doctor("112", 2, 0, "李二", "123lier", Department.INTERNAL, DoctorLevel.EXPERT, VisTiOnDay.AFTERNOON, 10.0);
//        Doctor doctor3 = new Doctor("113", 2, 0, "李三", "123lisan", Department.INTERNAL, DoctorLevel.GENERAL, VisTiOnDay.ALLDAY, 5.0);
//        Doctor doctor4 = new Doctor("114", 2, 0, "张一", "123zhangyi", Department.SURGERY, DoctorLevel.PROFESSOR, VisTiOnDay.MORNING, 15.0);
//        Doctor doctor5 = new Doctor("115", 2, 0, "张二", "123zhanger", Department.SURGERY, DoctorLevel.EXPERT, VisTiOnDay.AFTERNOON, 10.0);
//        Doctor doctor6 = new Doctor("116", 2, 0, "张三", "123zhangsan", Department.SURGERY, DoctorLevel.GENERAL, VisTiOnDay.ALLDAY, 5.0);
//        Doctor doctor7 = new Doctor("117", 2, 0, "王一", "123wangyi", Department.PADIATRICS, DoctorLevel.PROFESSOR, VisTiOnDay.MORNING, 15.0);
//        Doctor doctor8 = new Doctor("118", 2, 0, "王二", "123wanger", Department.PADIATRICS,DoctorLevel.EXPERT, VisTiOnDay.AFTERNOON, 10.0);
//        Doctor doctor9 = new Doctor("119", 2, 0, "王三", "123wangsan", Department.PADIATRICS, DoctorLevel.GENERAL, VisTiOnDay.ALLDAY, 5.0);
////
//
//        DOCTOR_LIST.add(doctor1);
//        DOCTOR_LIST.add(doctor2);
//        DOCTOR_LIST.add(doctor3);
//
//        DOCTOR_LIST.add(doctor4);
//        DOCTOR_LIST.add(doctor5);
//        DOCTOR_LIST.add(doctor6);
//
//        DOCTOR_LIST.add(doctor7);
//        DOCTOR_LIST.add(doctor8);
//        DOCTOR_LIST.add(doctor9);

//        DOCTOR_HASH_MAP.put(doctor1.getId(), doctor1);
//        DOCTOR_HASH_MAP.put(doctor2.getId(), doctor2);
//        DOCTOR_HASH_MAP.put(doctor3.getId(), doctor3);
//        DOCTOR_HASH_MAP.put(doctor4.getId(), doctor4);
//        DOCTOR_HASH_MAP.put(doctor5.getId(), doctor5);
//        DOCTOR_HASH_MAP.put(doctor6.getId(), doctor6);
//        DOCTOR_HASH_MAP.put(doctor7.getId(), doctor7);
//        DOCTOR_HASH_MAP.put(doctor8.getId(), doctor8);
//        DOCTOR_HASH_MAP.put(doctor9.getId(), doctor9);

        try {
            DOCTOR_LIST = FileIO.readObjectFromJsonFile("Doctor.json", new TypeReference<List<Doctor>>() {});
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        try {
            DOCTOR_HASH_MAP = FileIO.readObjectFromJsonFile("DoctorMap.json", new TypeReference<HashMap<String, Doctor>>() {});
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    @Override
    public List<Doctor> selectAllDoctor() {
        return DOCTOR_LIST;
    }

    @Override
    public HashMap<String, Doctor> IDToDoctor() {
        return DOCTOR_HASH_MAP;
    }

    @Override
    public void addDoctor(Doctor doctor) {
        DOCTOR_LIST.add(doctor);
        DOCTOR_HASH_MAP.put(doctor.getId(), doctor);
    }
}
